//品牌控制层
app.controller("brandController",function ($scope,$controller,brandService) {

    //继承baseController
    $controller('baseController',{$scope:$scope});

    //不分页查询品牌列表
    $scope.findAll=function () {
        brandService.findAll().success(

            function (data) {
                $scope.list=data.list;
            }
        );
    };



    //分页查询品牌列表
    $scope.findPage=function(pageNum,pageSize){
        brandService.findPage(pageNum,pageSize).success(
            function(data){
                $scope.list=data.list;//显示当前页内容
                $scope.paginationConf.totalItems=data.total;//更新总记录数
            }
        );
    };

    //保存(添加/修改)
    $scope.save=function () {

        var object = null;
        if ($scope.entity.id != null) {
            object=brandService.update($scope.entity);//如果id !=null,说明点击的是修改
        }else {
            object=brandService.add($scope.entity);
        }

        object.success(
            function (data) {
                if(data.success){
                    $scope.reloadList();//刷新
                }else {
                    alert(data.message);//弹出错误信息
                }
            }
        );
    };

    //根据id查询
    $scope.findOne=function(id){
        brandService.findOne(id).success(
            function (data) {
                $scope.entity=data;
            }
        );
    };



    //批量删除
    $scope.del=function () {
        brandService.del($scope.selectIds).success(

            function (data) {
                if (data.success) {
                    $scope.reloadList();//刷新
                } else {
                    alert(data.message);
                }
            }
        )
    };

    //根据条件分页搜索


    $scope.search=function(pageNum,pageSize){
        brandService.search(pageNum,pageSize,$scope.searchEntity).success(
            function(data){
                $scope.list=data.list;//显示当前页内容
                $scope.paginationConf.totalItems=data.total;//更新总记录数
            }
        );
    };

});